package com.turman.demo.fragment

import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import com.bumptech.glide.Glide
import com.turman.builibrary.banner.BBanner
import com.turman.builibrary.banner.core.BBannerModel
import com.turman.builibrary.banner.indicator.BNumberIndicator
import com.turman.common.ui.component.BaseFragment
import com.turman.demo.R

class ShowFragment : BaseFragment() {
    override fun getLayoutId(): Int = R.layout.frg_show

    override fun init() {
        val banner = layoutView.findViewById<BBanner>(R.id.banner)
        val data = mutableListOf<BBannerModel>(
            BBannerModel("https://www.devio.org/img/beauty_camera/beauty_camera1.jpg"),
            BBannerModel("https://www.devio.org/img/beauty_camera/beauty_camera2.jpg"),
            BBannerModel("https://www.devio.org/img/beauty_camera/beauty_camera3.jpg"),
            BBannerModel("https://www.devio.org/img/beauty_camera/beauty_camera4.jpg"),
            BBannerModel("https://www.devio.org/img/beauty_camera/beauty_camera5.jpg"),
            BBannerModel("https://www.devio.org/img/beauty_camera/beauty_camera6.jpg"),
            BBannerModel("https://www.devio.org/img/beauty_camera/beauty_camera7.jpg"),
        )

        banner.setAutoPlay(true)
        banner.setInterval(5000)
        banner.setScrollDuration(1000)
        banner.setIndicator(BNumberIndicator(requireContext()))
        banner.setBannerData(R.layout.banner_item, data)
        banner.setBindAdapter { holder, model, position ->
            holder?.findViewById<ImageView>(R.id.img)?.let {
                Glide.with(this@ShowFragment).load(model.url).into(it)
            }
            holder?.findViewById<TextView>(R.id.text)?.let {
                it.text = model.url
            }
        }

        banner.setOnBannerChickListener { viewHolder, bannerMo, position ->
            Toast.makeText(requireContext(), "点击了${position + 1}个", Toast.LENGTH_SHORT).show()
        }
    }
}